package com.offcn.controller;

import com.offcn.entity.Book;
import com.offcn.service.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class BookController{
    @Resource
    private BookServiceImpl bookService;
    @DeleteMapping("/book/delete/{id}")
    public int delete(@PathVariable("id") int id) {
        int i = bookService.delete(id);
        return i;
    }
    @PutMapping("/book/put/")
    public int update(@RequestBody Book book) {
        int i = bookService.update(book);
        return i;
    }

    @PostMapping("/book/post/")
    public int add(@RequestBody Book book) {
      int i =  bookService.add(book);
      return i;
    }

    @GetMapping("/book/get/")
    public List<Book> select() {
        List<Book> list = bookService.select();
        return list;
    }
    @GetMapping("/book/get/{id}")
    public Book selectOne(@PathVariable("id") int id){
        Book book = bookService.selectOne(id);
        return book;
    }
}
